package com.wali.modules.bil.control;

import com.wali.common.ccp.exception.CcpException;
import com.wali.common.enums.ErrorCodeEnum;
import com.wali.common.web.BaseController;
import com.wali.modules.bil.bo.BilLogisticsBO;
import com.wali.modules.bil.service.BilLogisticsService;
import com.wali.modules.bil.vo.BilLogisticsVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @author walixu
 * @ClassName com.wali.modules.bil.control
 * @Description 物流信息controller类
 * @email wali.xu@kpmg.com
 * @date 22/02/2019 7:43 下午
 */
@Controller
@RequestMapping(value = "")
public class BilLogisticsController extends BaseController {

    @Autowired
    private BilLogisticsService bilLogisticsService;

    /**
     * @param
     * @return
     * @throws
     * @Title listBilLogisticsT
     * @Description 查询符合条件的运单物流信息
     */
    @RequestMapping(value = "/bil/listBilLogistics", method = RequestMethod.GET)
    public ResponseEntity<String> listBilLogistics(BilLogisticsBO bilLogisticsBO) {
        int code = ErrorCodeEnum.ERROR_INTERNAL_CODE.getCode();
        String msg = ErrorCodeEnum.ERROR_INTERNAL_CODE.getMessage();

        try {
            if (StringUtils.isBlank(bilLogisticsBO.getWaybillNo())) {
                return getResponseEntity(code, msg);
            }

            List<BilLogisticsVO> bilLogisticsList = bilLogisticsService.listBilLogistics(bilLogisticsBO);
            code = ErrorCodeEnum.SUCCESS_CODE.getCode();
            msg = ErrorCodeEnum.SUCCESS_CODE.getMessage();
            return getResponseEntity(code, msg, bilLogisticsList);
        } catch (CcpException e) {
            logger.error(e.getMessage(), e);
            code = e.getException().getCode();
            msg = e.getException().getMessage();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        return getResponseEntity(code, msg);
    }

    /**
     * @param
     * @return
     * @throws
     * @Title listBilLogisticsT
     * @Description 对外查询符合条件的运单物流信息
     */
    @RequestMapping(value = "/listBilLogistics")
    public ResponseEntity<String> listBilLogisticsT(BilLogisticsBO bilLogisticsBO) {
        return listBilLogistics(bilLogisticsBO);
    }
}
